﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>ArcGIS叠加单值专题图</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">
<style>
    html, body, #map {
        height:100%;
        width:100%;
        margin:0;
        padding:0;
    }
    body {
        height: 90%;
        width: 100%;;
        background-color:#FFF;
        overflow:hidden;
        font-family:"Trebuchet MS";
    }
</style>
    <link href='./css/bootstrap.min.css' rel='stylesheet' />
    <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"></script>
<script src="../libs/SuperMap.Include.js"></script>
<script src="js/iConnector/iConnectorArcGIS.js"></script>
<script>
    dojo.require("esri.map");
    var map,layer;
    var host = document.location.toString().match(/file:\/\//) ? "http://localhost:8090" : 'http://' + document.location.host;
    url = host + "/iserver/services/map-china400/rest/maps/China";
    function Init() {
        //初始化arcgis的地图
        map = new esri.Map("map", { center: [105,39],zoom: 4 });
        //初始化arcgis的地图图层
        var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer");
        //添加底图
        map.addLayer(layer);
    }
    //添加单值专题图
    function addThemeUnique() {
        layer&&map.removeLayer(layer);
        var themeService = new SuperMap.REST.ThemeService(url, {eventListeners:{"processCompleted": themeCompleted, "processFailed": themeFailed}});
        var style1, style2, style3, style4, style5, style6;
        //设置style
        style1 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(248, 203, 249),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style2 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(196, 255, 189),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style3 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(255, 173, 173),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style4 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(255, 239, 168),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style5 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(173, 209, 255),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style6 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(132, 164, 232),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        //设置单值的属性
        var themeUniqueIteme1 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "黑龙江省",
                    style: style1
                }),
                themeUniqueIteme2 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "湖北省",
                    style: style2
                }),
                themeUniqueIteme3 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "吉林省",
                    style: style3
                }),
                themeUniqueIteme4 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "内蒙古自治区",
                    style: style4
                }),
                themeUniqueIteme5 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "青海省",
                    style: style5
                }),
                themeUniqueIteme6 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "新疆维吾尔自治区",
                    style: style6
                }),
                themeUniqueIteme7 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "云南省",
                    style: style1
                }),
                themeUniqueIteme8 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "四川省",
                    style: style4
                }),
                themeUniqueIteme9 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "贵州省",
                    style: style3
                }),
                themeUniqueIteme10 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "甘肃省",
                    style: style3
                }),
                themeUniqueIteme11 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "宁夏回族自治区",
                    style: style5
                }),
                themeUniqueIteme12 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "重庆市",
                    style: style6
                }),
                themeUniqueIteme13 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "山东省",
                    style: style1
                }),
                themeUniqueIteme14 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "安徽省",
                    style: style2
                }),
                themeUniqueIteme15 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "江西省",
                    style: style3
                }),
                themeUniqueIteme16 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "浙江省",
                    style: style4
                }),
                themeUniqueIteme17 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "台湾省",
                    style: style2
                }),
                themeUniqueIteme18 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "江苏省",
                    style: style6
                }),
                themeUniqueIteme19 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "湖南省",
                    style: style5
                }),
                themeUniqueIteme20 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "河南省",
                    style: style4
                }),
                themeUniqueIteme21 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "河北省",
                    style: style3
                }),
                themeUniqueIteme22 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "福建省",
                    style: style5
                }),
                themeUniqueIteme23 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "广西壮族自治区",
                    style: style6
                }),
                themeUniqueIteme24 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "西藏自治区",
                    style: style2
                }),
                themeUniqueIteme25 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "广东省",
                    style: style4
                }),
                themeUniqueIteme26 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "山西省",
                    style: style2
                }),
                themeUniqueIteme27 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "陕西省",
                    style: style1
                }),
                themeUniqueIteme28 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "天津市",
                    style: style5
                }),
                themeUniqueIteme29 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "北京市",
                    style: style2
                }),

                themeUniqueIteme30 = new SuperMap.REST.ThemeUniqueItem({
                    unique: "辽宁省",
                    style: style1
                });

        var themeUniqueItemes=[themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3, themeUniqueIteme4, themeUniqueIteme5, themeUniqueIteme6,themeUniqueIteme7,themeUniqueIteme8,themeUniqueIteme9,themeUniqueIteme10,themeUniqueIteme11,themeUniqueIteme12, themeUniqueIteme13,themeUniqueIteme14,themeUniqueIteme15,themeUniqueIteme16,themeUniqueIteme17,themeUniqueIteme18,themeUniqueIteme19,themeUniqueIteme20,themeUniqueIteme21,themeUniqueIteme22,themeUniqueIteme23,themeUniqueIteme24,themeUniqueIteme25,themeUniqueIteme26,themeUniqueIteme27,themeUniqueIteme28,themeUniqueIteme29,themeUniqueIteme30];
        //设置单值专题图参数
        var themeUnique = new SuperMap.REST.ThemeUnique({
            uniqueExpression: "Name",
            items: themeUniqueItemes,
            defaultStyle: style1
        });
        //设置专题图参数
        themeParameters = new SuperMap.REST.ThemeParameters({
            datasetNames: ["China_Province_pg"],
            dataSourceNames: ["China"],
            themes: [themeUnique]
        });
        //向iserver发送请求
        themeService.processAsync(themeParameters);
    }
    //生成专题图后将其叠加到arcgis地图上面
    function themeCompleted(themeEventArgs) {
        if(themeEventArgs.result.resourceInfo.id) {
            //通过iConnector生成可以在arcgis地图上叠加的单值专题图图层
             layer = SuperMap.Web.iConnector.ArcGIS.getLayer(url,{layersID:themeEventArgs.result.resourceInfo.id});
            map.addLayer(layer);
        }
    }

    function themeFailed(serviceFailedEventArgs) {
        alert(serviceFailedEventArgs.error.errorMsg);
    }
    function removeTheme(){
        map.removeLayer(layer);
    }

    dojo.addOnLoad(Init);
</script>
</head>
<body class="claro" >
<input type="button" class="btn" value="创建单值专题图" onclick="addThemeUnique()" />
<input type="button" class="btn" value="移除单值专题图" onclick="removeTheme()" />
<div id="map" style="margin-top: 10px;"></div>

</body>
</html> 